package org.swim.servlet;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.swim.session.FriendshipManagerRemote;

/**
 * Servlet implementation class DenyFriendRequest
 */
public class DenyFriendRequest extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DenyFriendRequest() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        int friendRequest = Integer.parseInt(request.getParameter("id"));
        InitialContext ic;
        try {
			ic = new InitialContext();
			FriendshipManagerRemote friendshipManager = (FriendshipManagerRemote)ic.lookup("FriendshipManagerRemote");
			friendshipManager.denyFriendship(friendRequest);
		} catch (NamingException e) {
			e.printStackTrace();
		}
		request.getRequestDispatcher("ViewFriendsRequests").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
